package CreateThread;

class MyRunnable implements Runnable {
    //实现了Runnable接口，需要重写里面的方法
    @Override
    public void run() {
        while(true) {
            System.out.println("新线程的调度");
            try {
                Thread.sleep(1_000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class demo2 {
    public static void main(String[] args) throws InterruptedException {
        //创建Thread的实例
        MyRunnable t = new MyRunnable();
        Thread thread = new Thread(t);

        //启动线程
        thread.start();
        while (true) {
            System.out.println("主线程的调度");
            Thread.sleep(1_000);
        }
    }
}